import { createStore } from 'vuex'


const store = createStore({


  types: {
    SET_LOCATION: "SET_LOCATION",
    SET_ADDRESS: "SET_ADDRESS"
  },


  state: {
    location: {},
    address: ''
  },


  getters: {
    location: (state) => state.location,
    address: (state) => state.address
  },

  mutations: {
    // [types.SET_LOCATION](state,location){
    tsetlocation(state, location) {
      if (location) {
        state.location = location;
      } else {
        state.location = null;
      }
    },

    // [types.SET_ADDRESS](state,address){
    tsetaddress(state, address) {
      if (address) {
        state.address = address;
      } else {
        state.address = '';
      }
    },
  },

  actions: {

    //使用context上下文执行mutations里面的方法

    // setLocation: ({ commit }, location,context) => {
      setLocation: ({commit},location) => {
      // commit(types.SET_LOCATION,location);
      // commit(tsetlocation, location);
      // context.commit('tsetlocation',location);
      commit('tsetlocation',location)

    },
    // setAddress: ({ commit }, address,context) => {
      setAddress: (context,address) => {
      // commit(types.SET_ADDRESS,address);
      // commit(tsetaddress, location);
      context.commit("tsetaddress",address);
    }
  }
})
export default store;